package com.qd.pay.config;

import com.qd.pay.thread.OrderNotifyErrorThread;
import com.qd.pay.thread.OrderNotifyThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author sjk
 */
@Slf4j
@Component
public class ProcessConfig {

    OrderNotifyErrorThread orderNotifyErrorThread;
    OrderNotifyThread orderNotifyThread;

    @Bean
    OrderNotifyErrorThread getOrderNotifyErrorThread() {
        orderNotifyErrorThread = new OrderNotifyErrorThread();
        orderNotifyErrorThread.setName("OrderNotifyErrorThread");
        return orderNotifyErrorThread;
    }

    @Bean
    @PostConstruct
    OrderNotifyThread getOrderNotifyThread() {
        orderNotifyThread = new OrderNotifyThread();
        orderNotifyThread.setName("OrderNotifyThread");
        return orderNotifyThread;
    }

    public void destroy() {
        log.info("orderNotifyErrorThread,orderNotifyThread destroy");
        if (null != orderNotifyErrorThread) {
            orderNotifyErrorThread.doDone();
        }
        if (null != orderNotifyThread) {
            orderNotifyThread.doDone();
        }
    }
}
